package com.xingfudazi.web.controller.app;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.xingfudazi.app.domain.AppNotice;
import com.xingfudazi.app.service.IAppNoticeService;
import com.xingfudazi.common.annotation.Log;
import com.xingfudazi.common.core.controller.BaseController;
import com.xingfudazi.common.core.domain.AjaxResult;
import com.xingfudazi.common.core.page.TableDataInfo;
import com.xingfudazi.common.enums.BusinessType;
import com.xingfudazi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 通知Controller
 * 
 * @author ruoyi
 * @date 2024-06-21
 */
@RestController
@RequestMapping("/app/notice")
public class AppNoticeController extends BaseController
{
    @Autowired
    private IAppNoticeService appNoticeService;

    /**
     * 查询通知列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AppNotice appNotice)
    {
        startPage();
        List<AppNotice> list = appNoticeService.selectAppNoticeList(appNotice);
        return getDataTable(list);
    }

    /**
     * 导出通知列表
     */
    @Log(title = "通知", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppNotice appNotice)
    {
        List<AppNotice> list = appNoticeService.selectAppNoticeList(appNotice);
        ExcelUtil<AppNotice> util = new ExcelUtil<AppNotice>(AppNotice.class);
        util.exportExcel(response, list, "通知数据");
    }

    /**
     * 获取通知详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(appNoticeService.selectAppNoticeById(id));
    }

    /**
     * 新增通知
     */
    @Log(title = "通知", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppNotice appNotice)
    {
        return toAjax(appNoticeService.insertAppNotice(appNotice));
    }

    /**
     * 修改通知
     */
    @Log(title = "通知", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppNotice appNotice)
    {
        return toAjax(appNoticeService.updateAppNotice(appNotice));
    }

}
